<?php

class m_config extends CI_Model{
	
	function _list($data){
		extract($data);
		$sql = "SELECT 
					config_dashboard,
					config_refresh,
					config_suara,
					config_id
				FROM m_config
				WHERE 
					config_active = '1'
		";
		
		if (@$config_dashboard != "") $sql .= " AND config_dashboard like '%".@$config_dashboard."%'";
		if (@$config_refresh != "") $sql .= " AND config_refresh like '%".@$config_refresh."%'";
		
		$query = $this->db->query($sql);
		$records = $query->num_rows();
		
		$sql = "SELECT * FROM (".$sql.") k LIMIT ".(($page - 1) * $rows)." , ".$rows;
		$query = $this->db->query($sql);
		$result = $query->result();
		
		return '{ 
		  "total": "'.ceil($records / $rows).'", 
		  "page": "'.$page.'", 
		  "records": "'.$records .'",
		  "rows" : '.json_encode($result).'
		}';
	}
	
    function _data(){
        $sql = "SELECT 
					config_dashboard,
					config_refresh,
					config_suara,
					config_id
				FROM m_config
				WHERE 
					config_active = '1'
		";
		$query = $this->db->query($sql);
        $row = $query->row();
        return $row;
    }
    
	function _insert($data){
		$this->db->insert('m_config',$data);
		return 1;
	}
	
	function _update($data,$id){
		$this->db->where('config_id',$id);
		$this->db->update('m_config',$data);
		return 1;
	}
	
	function _delete($data,$id){
		$this->db->where('config_id',$id);
		$this->db->update('m_config',$data);
		return 1;
	}
}